Passed
Push — master ( 6ba010...db2040 )
by Alexander
02:32
created

testrun_actions.js ➔ ... ➔ success   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 24
rs 9.0833
c 0
b 0
f 0
cc 5
nop 1
nc 6

2 Functions

Rating   Name   Duplication   Size   Complexity  
A testrun_actions.js ➔ ... ➔ data.forEach 0 8 1
A testrun_actions.js ➔ updateTagContainer 0 15 1
1
Nitrate.TestRuns = {};
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2
Nitrate.TestRuns.Details = {};
3
Nitrate.TestRuns.Execute = {}
4
Nitrate.TestRuns.AssignCase = {}
5
6
7
Nitrate.TestRuns.Details.on_load = function() {
8
  setAddTagAutocomplete();
9
10
  // Observe the interface buttons
11
  jQ('#id_check_all_button').bind('click', function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
12
    toggleAllCheckBoxes(this, 'id_table_cases', 'case_run');
13
  });
14
15
  if (jQ('#id_check_box_highlight').attr('checked')) {
16
    jQ('.mine').addClass('highlight');
17
  }
18
19
  jQ('#id_check_box_highlight').bind('click', function(e) {
20
    e = jQ('.mine');
21
    this.checked && e.addClass('highlight') || e.removeClass('highlight');
22
  });
23
24
  jQ('#id_blind_all_link').bind('click', function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
25
    if (!jQ('td[id^="id_loading_"]').length) {
26
      jQ(this).removeClass('locked');
27
    }
28
    if (jQ(this).is('.locked')) {
29
      //To disable the 'expand all' until all case runs are expanded.
30
      return false;
31
    } else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
32
      jQ(this).addClass('locked');
33
      var element = jQ(this).children();
34
      if (element.is('.collapse-all')) {
35
        this.title = "Collapse all cases";
36
        blinddownAllCases(element[0]);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
37
      } else {
38
        this.title = "Expand all cases";
39
        blindupAllCases(element[0]);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
40
      }
41
    }
42
  });
43
44
  // Observe the case run toggle and the comment form
45
  var toggle_case_run = function(e) {
46
    var c = jQ(this).parent(); // Container
47
    var c_container = c.next(); // Content Containers
48
    var case_id = c.find('input[name="case"]')[0].value;
49
    var case_run_id = c.find('input[name="case_run"]')[0].value;
50
    var case_text_version = c.find('input[name="case_text_version"]')[0].value;
51
    var type = 'case_run';
0 ignored issues
show
Unused Code introduced by
The variable type seems to be never used. Consider removing it.
Loading history...
52
    var callback = function(t) {
53
      // Observe the update case run stauts/comment form
54
      c_container.parent().find('.update_form')
55
        .unbind('submit').bind('submit', updateCaseRunStatus);
56
57
      // Observe the delete comment form
58
      var refresh_case = function(t) {
0 ignored issues
show
Unused Code introduced by
The parameter t is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
59
        constructCaseRunZone(c_container[0], c[0], case_id);
60
      };
61
62
      var rc_callback = function(e) {
63
        e.stopPropagation();
64
        e.preventDefault();
65
        if (!window.confirm(default_messages.confirm.remove_comment)) {
0 ignored issues
show
Bug introduced by
The variable default_messages seems to be never declared. If this is a global, consider adding a /** global: default_messages */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
66
          return false;
67
        }
68
        removeComment(this, refresh_case);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
69
      };
70
      c_container.parent().find('.form_comment')
71
        .unbind('submit').bind('submit', rc_callback);
72
      c_container.find('.js-status-button').bind('click', function() {
73
        this.form.value.value = jQ(this).data('formvalue');
74
      });
75
      c_container.find('.js-show-comments').bind('click', function() {
76
        toggleDiv(this, jQ(this).data('param'));
77
      });
78
      c_container.find('.js-show-changelog').bind('click', function() {
79
        toggleDiv(this, jQ(this).data('param'));
80
      });
81
      c_container.find('.js-file-caserun-bug').bind('click', function(){
82
        var params = jQ(this).data('params');
83
        fileCaseRunBug(params[0], c[0], c_container[0], params[1], params[2]);
84
      });
85
      c_container.find('.js-add-caserun-bug').bind('click', function(){
86
        var params = jQ(this).data('params');
87
        addCaseRunBug(params[0], c[0], c_container[0], params[1], params[2]);
88
      });
89
      c_container.find('.js-remove-caserun-bug').bind('click', function(){
90
        var params = jQ(this).data('params');
91
        removeCaseBug(params[1], params[2], params[3]);
92
      });
93
      c_container.find('.js-add-testlog').bind('click', function(){
94
        var params = jQ(this).data('params');
95
        addLinkToCaseRun(this, params[0], params[1]);
96
      });
97
      c_container.find('.js-remove-testlog').bind('click', function(){
98
        removeLink(this, window.parseInt(jQ(this).data('param')));
99
      });
100
    };
101
102
    toggleTestCaseRunPane({
103
      'callback': callback,
104
      'caseId': case_id,
105
      'caserunId': case_run_id,
106
      'caseTextVersion': case_text_version,
107
      'caserunRowContainer': c,
108
      'expandPaneContainer': c_container
109
    });
110
  };
111
  jQ('.expandable').bind('click', toggle_case_run);
112
113
  // Auto show the case run contents.
114
  if (window.location.hash != '') {
115
    fireEvent(jQ('a[href=\"' + window.location.hash + '\"]')[0], 'click');
116
  };
117
118
  // Filter Case-Run
119
  if (jQ('#filter_case_run').length) {
120
    jQ('#filter_case_run').bind('click',function(e){
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
121
      if (jQ('#id_filter').is(':hidden')){
122
        jQ('#id_filter').show();
123
        jQ(this).html(default_messages.link.hide_filter);
0 ignored issues
show
Bug introduced by
The variable default_messages seems to be never declared. If this is a global, consider adding a /** global: default_messages */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
124
      } else {
125
        jQ('#id_filter').hide();
126
        jQ(this).html(default_messages.link.show_filter);
127
      }
128
    });
129
  }
130
  //bind click to status btn
131
  jQ('.btn_status').live('click', function() {
132
    var from = jQ(this).siblings('.btn_status:disabled')[0].title;
133
    var to = this.title;
134
    if (jQ('span#' + to + ' a').text() === '0') {
135
      var htmlstr = "[<a href='javascript:void(0)' onclick=\"showCaseRunsWithSelectedStatus(jQ('#id_filter')[0], '"
136
        + jQ(this).attr('crs_id')+"')\">0</a>]";
137
      jQ('span#' + to).html(htmlstr);
138
    }
139
    if (jQ('span#' + from + ' a').text() === '1') {
140
      jQ('span#' + from).html("[<a>1</a>]");
141
    }
142
    jQ('span#' + to + ' a').text(window.parseInt(jQ('span#' + to + ' a').text()) + 1);
143
    jQ('span#' + from + ' a').text(window.parseInt(jQ('span#' + from + ' a').text()) - 1);
144
145
    var caseRunCount = window.parseInt(jQ('span#TOTAL').next().text()) || 0;
146
    var passedCaseRunCount = window.parseInt(jQ('span#PASSED a').text()) || 0;
147
    var errorCaseRunCount = window.parseInt(jQ('span#ERROR a').text()) || 0;
148
    var failedCaseRunCount = window.parseInt(jQ('span#FAILED a').text()) || 0;
149
    var waivedCaseRunCount = window.parseInt(jQ('span#WAIVED a').text()) || 0;
150
    var completePercent = 100 * ((passedCaseRunCount + errorCaseRunCount + failedCaseRunCount
151
      + waivedCaseRunCount) / caseRunCount).toFixed(2);
152
    var failedPercent = 100 * ((errorCaseRunCount + failedCaseRunCount) / (passedCaseRunCount
153
      + errorCaseRunCount + failedCaseRunCount + waivedCaseRunCount)).toFixed(2);
154
155
    jQ('span#complete_percent').text(completePercent);
156
    jQ('div.progress-inner').attr('style', 'width:' + completePercent + '%');
157
    jQ('div.progress-failed').attr('style', 'width:' + failedPercent + '%');
158
  });
159
160
  jQ('#btn_edit').bind('click', function() {
161
    var params = jQ(this).data('params');
162
    window.location.href = params[0] + '?from_plan=' + params[1];
163
  });
164
  jQ('#btn_clone').bind('click', function() {
165
    postToURL(jQ(this).data('param'), serializeCaseRunFromInputList('id_table_cases','case_run'));
166
  });
167
  jQ('#btn_delete').bind('click', function() {
168
    window.location.href = jQ(this).data('param');
169
  });
170
171
  bindJSRemoveTagButton();
172
  jQ('.js-add-tag').bind('click', function() {
173
    addRunTag(jQ('.js-tag-ul')[0], jQ(this).data('param'));
174
  });
175
  jQ('.js-set-running').bind('click', function() {
176
    window.location.href = jQ(this).data('param') + '?finished=0';
177
  });
178
  jQ('.js-set-finished').bind('click', function() {
179
    window.location.href = jQ(this).data('param') + '?finished=1';
180
  });
181
  jQ('.js-del-case').bind('click', function() {
182
    delCaseRun(jQ(this).data('param'));
183
  });
184
  jQ('.js-update-case').bind('click', function() {
185
    postToURL(jQ(this).data('param'), serializeCaseRunFromInputList('id_table_cases', 'case_run'));
186
  });
187
  jQ('.js-change-assignee').bind('click', function() {
188
    changeCaseRunAssignee();
189
  });
190
  jQ('.js-add-bugs').bind('click', function() {
191
    updateBugs('add');
192
  });
193
  jQ('.js-remove-bugs').bind('click', function() {
194
    updateBugs('remove');
195
  });
196
  jQ('.js-show-commentdialog').bind('click', function() {
197
    showCommentForm();
198
  });
199
  jQ('.js-add-cc').bind('click', function() {
200
    addRunCC(jQ(this).data('param'), jQ('.js-cc-ul')[0]);
201
  });
202
  jQ('.js-remove-cc').bind('click', function() {
203
    var params = jQ(this).data('params');
204
    removeRunCC(params[0], params[1], jQ('.js-cc-ul')[0]);
205
  });
206
  jQ('.js-caserun-total').bind('click', function() {
207
    showCaseRunsWithSelectedStatus(jQ('#id_filter')[0], '');
208
  });
209
  jQ('.js-status-subtotal').bind('click', function() {
210
    showCaseRunsWithSelectedStatus(jQ('#id_filter')[0], jQ(this).data('param'));
211
  });
212
};
213
214
Nitrate.TestRuns.AssignCase.on_load = function() {
215
  if (jQ('#id_check_all_button').length) {
216
    jQ('#id_check_all_button').bind('click', function(m) {
0 ignored issues
show
Unused Code introduced by
The parameter m is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
217
      toggleAllCheckBoxes(this, 'id_table_cases', 'case');
218
    });
219
  }
220
221
  jQ('input[name="case"]').bind('click', function(t) {
0 ignored issues
show
Unused Code introduced by
The parameter t is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
222
    if (this.checked) {
223
      jQ(this).closest('tr').addClass('selection_row');
224
      jQ(this).parent().siblings().eq(7).html('<div class="apply_icon"></div>');
225
    } else {
226
      jQ(this).closest('tr').removeClass('selection_row');
227
      jQ(this).parent().siblings().eq(7).html('');
228
    }
229
  });
230
231
  jQ('.js-how-assign-case').bind('click', function() {
232
    jQ('#help_assign').show();
233
  });
234
  jQ('.js-close-how-assign').bind('click', function() {
235
    jQ('#help_assign').hide();
236
  });
237
  jQ('.js-toggle-button, .js-case-summary').bind('click', function() {
238
    toggleTestCaseContents(jQ(this).data('param'));
239
  });
240
};
241
242
243
function updateRunStatus(object_pk, value, callback) {
244
  jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
245
    'url': '/runs/case-run-update-status/',
246
    'type': 'POST',
247
    'data': {'object_pk': object_pk, 'status_id': value },
248
    'success': function (data, textStatus, jqXHR) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter jqXHR is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter textStatus is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
249
      callback();
250
    },
251
    'error': function (jqXHR, textStatus, errorThrown) {
0 ignored issues
show
Unused Code introduced by
The parameter errorThrown is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter textStatus is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
252
      json_failure(jqXHR);
253
    }
254
  });
255
}
256
257
var updateCaseRunStatus = function(e) {
258
  e.stopPropagation();
259
  e.preventDefault();
260
  var container = jQ(this).parents().eq(3);
261
  var parent = container.parent();
262
  var title = parent.prev();
263
  var link = title.find('.expandable')[0];
264
  var parameters = Nitrate.Utils.formSerialize(this);
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
265
  var object_pk = parameters['object_pk'];
266
  var value = parameters['value'];
267
268
  // Callback when
269
  var callback = function(t) {
0 ignored issues
show
Unused Code introduced by
The parameter t is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
270
    // Update the contents
271
    if (parameters['value'] != '') {
272
      // Update the case run status icon
273
      var crs = Nitrate.TestRuns.CaseRunStatus;
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
274
      title.find('.icon_status').each(function(index) {
0 ignored issues
show
Unused Code introduced by
The parameter index is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
275
        for (i in crs) {
0 ignored issues
show
Bug introduced by
The variable i seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.i.
Loading history...
276
          if (typeof crs[i] === 'string' && jQ(this).is('.btn_' + crs[i])) {
277
            jQ(this).removeClass('btn_' + crs[i]);
278
          }
279
        }
280
        jQ(this).addClass('btn_' + Nitrate.TestRuns.CaseRunStatus[value - 1]);
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
281
      });
282
283
      // Update related people
284
      var usr = Nitrate.User;
285
      title.find('.link_tested_by').each(function(i) {
0 ignored issues
show
Unused Code introduced by
The parameter i is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
286
        jQ(this).html(usr.username);
287
      });
288
    }
289
290
    // Mark the case run to mine
291
    if (!title.is('.mine')) {
292
      title.addClass('mine');
293
    }
294
295
    // Blind down next case
296
    fireEvent(link, 'click');
297
    if (jQ('#id_check_box_auto_blinddown').attr('checked') && parameters['value'] != '') {
298
      var next_title = parent.next();
299
      if (!next_title.length) {
300
        return false;
301
      }
302
      if (next_title.next().is(':hidden')) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if next_title.next().is(":hidden") is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
303
        fireEvent(next_title.find('.expandable')[0], 'click');
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
304
      }
305
    } else {
306
      fireEvent(link, 'click');
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
307
    }
308
  };
309
310
  // Add comment
311
  if (parameters['comment'] != '') {
312
    // Reset the content to loading
313
    var ajax_loading = getAjaxLoading();
314
    ajax_loading.id = 'id_loading_' + parameters['case_id'];
315
    container.html(ajax_loading);
316
    var c = jQ('<div>');
317
    if (parameters['value'] != '') {
318
      submitComment(c[0], parameters);
319
    } else {
320
      submitComment(c[0], parameters, callback);
321
    }
322
  }
323
324
  // Update the object when changing the status
325
  if (parameters['value'] != '') {
326
    // Reset the content to loading
327
    var ajax_loading = getAjaxLoading();
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable ajax_loading already seems to be declared on line 313. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
328
    ajax_loading.id = 'id_loading_' + parameters['case_id'];
329
    container.html(ajax_loading);
330
    updateRunStatus([object_pk], value, callback);
331
  }
332
};
333
334
335
function constructCaseRunZone(container, title_container, case_id) {
336
  var link = jQ(title_container).find('.expandable')[0];
337
  if (container) {
338
    var td = jQ('<td>', {'id': 'id_loading_' + case_id, 'colspan': 12 });
339
    td.html(getAjaxLoading());
340
    jQ(container).html(td);
341
  }
342
343
  if (title_container) {
344
    fireEvent(link, 'click');
345
    fireEvent(link, 'click');
346
  }
347
}
348
349
350
//////////////////////////////////////////////////////////////////////////////////////////////
351
////////   AddIssueDialog Definition //////////////
352
353
354
/*
355
 * Dialog to allow user to add sort of issue keys to case run(s).
356
 *
357
 * Here, issue key is a general to whatever the issue tracker system is.
358
 *
359
 * options:
360
 * @param extraFormHiddenData: used for providing extra data for specific AJAX request.
361
 * @param onSubmit: callback function when user click Add button
362
 * @param action: string - Add or Remove. Default is Add
363
 */
364
/*
365
 * FIXME: which namespace is proper to hold this dialog class?
366
 */
367
function AddIssueDialog(options) {
368
  this.onSubmit = options.onSubmit;
369
  if (this.onSubmit !== undefined && typeof this.onSubmit !== "function") {
370
    throw new Error("onSubmit should be a function object.");
371
  }
372
  this.extraFormHiddenData = options.extraFormHiddenData;
373
  if (this.extraFormHiddenData !== undefined && typeof this.extraFormHiddenData !== "object") {
374
    throw new Error("extraFormHiddenData sould be an object if present.");
375
  }
376
377
  this.action = options.action;
378
  if (this.action === undefined) {
379
    this.action = "Add";
380
  }
381
382
  this.a = options.a;
383
  if (this.a === undefined) {
384
    this.a = this.action.toLowerCase();
385
  }
386
387
  if (options.hasOwnProperty("show_bug_id_field")) {
388
    this.show_bug_id_field = options.show_bug_id_field;
389
  } else {
390
    this.show_bug_id_field = false;
391
  }
392
}
393
394
395
AddIssueDialog.prototype.show = function () {
396
  var dialog = jQ("#dialog")[0];
397
  if (dialog == null) {
0 ignored issues
show
Best Practice introduced by
Comparing dialog to null using the == operator is not safe. Consider using === instead.
Loading history...
398
    throw new Error("No HTML element with ID dialog. This should not happen in the runtime.");
399
  }
400
401
  var hiddenPart = [];
402
  if (this.extraFormHiddenData !== undefined) {
403
    for (var name_attr in this.extraFormHiddenData) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
404
      hiddenPart.push({'name': name_attr, 'value': this.extraFormHiddenData[name_attr]});
405
    }
406
  }
407
408
  var template = Handlebars.compile(jQ("#add_issue_form_template").html());
0 ignored issues
show
Bug introduced by
The variable Handlebars seems to be never declared. If this is a global, consider adding a /** global: Handlebars */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
409
  var context = {
410
    'hiddenFields': hiddenPart,
411
    'action_button_text': this.action,
412
    'show_bug_id_field': this.show_bug_id_field || this.action === 'Add',
413
    'show_add_to_bugzilla_checkbox': this.action === 'Add',
414
    'a': this.a,
415
  };
416
417
  jQ('#dialog').html(template(context))
418
    .find('.js-cancel-button').bind('click', function() {
419
      jQ('#dialog').hide();
420
    })
421
    .end().show();
422
423
  this.form = jQ("#add_issue_form")[0];
424
425
  // Used for following event callbacks to ref this dialog's instance
426
  var that = this;
427
428
  // Set custom callback functions
429
  if (this.onSubmit !== undefined) {
430
    jQ(this.form).bind('submit', function (form_event) {
431
      that.onSubmit(form_event, that);
432
    });
433
  }
434
};
435
436
AddIssueDialog.prototype.get_data = function () {
437
  var form_data = Nitrate.Utils.formSerialize(this.form);
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
438
  form_data.bug_validation_regexp = jQ('#bug_system_id option:selected').data('validation-regexp');
439
  return form_data;
440
};
441
442
//// end of AddIssueDialog definition /////////
443
/////////////////////////////////////////////////////////////////////////////////////////////
444
445
function getIssueTrackerNewURL() {
446
}
447
448
function fileCaseRunBug(run_id, title_container, container, case_id, case_run_id, callback) {
449
  var dialog = new AddIssueDialog({
450
    'action': 'Report',
451
    'a': 'file',
452
    'extraFormHiddenData': { 'case_run': case_run_id, 'case': case_id },
453
    'onSubmit': function (e, dialog) {
454
      e.stopPropagation();
455
      e.preventDefault();
456
457
      form_data = dialog.get_data();
0 ignored issues
show
Bug introduced by
The variable form_data seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.form_data.
Loading history...
458
459
      var success_callback = function(t) {
460
        jQ('#dialog').hide();
461
        var returnobj = t;
462
463
        if (returnobj.rc === 0) {
464
          if (callback) {
465
            return callback();
466
          }
467
468
          window.open(returnobj.response, '_blank');
469
          return true;
470
        } else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
471
          window.alert(returnobj.response);
472
          return false;
473
        }
474
      };
475
476
      var url = Nitrate.http.URLConf.reverse({ 'name': 'case_run_bug', 'arguments': {'id': case_run_id} });
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
477
      jQ.ajax({ url: url, dataType: 'json', data: form_data, success: success_callback });
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
478
    }
479
  });
480
481
  dialog.show();
482
}
483
484
function addCaseRunBug(run_id, title_container, container, case_id, case_run_id, callback) {
485
  var dialog = new AddIssueDialog({
486
    'extraFormHiddenData': { 'case_run': case_run_id, 'case': case_id },
487
    'onSubmit': function (e, dialog) {
488
      e.stopPropagation();
489
      e.preventDefault();
490
491
      form_data = dialog.get_data();
0 ignored issues
show
Bug introduced by
The variable form_data seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.form_data.
Loading history...
492
493
      form_data.bug_id = form_data.bug_id.trim();
494
      if (!form_data.bug_id.length) {
495
        return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
496
      }
497
498
      if (!validateIssueID(form_data.bug_validation_regexp, form_data.bug_id)) {
499
        return false;
500
      }
501
502
      var success_callback = function(t) {
503
        jQ('#dialog').hide();
504
        var returnobj = t;
505
506
        if (returnobj.rc === 0) {
507
          if (callback) {
508
            return callback();
509
          }
510
511
          // Update bugs count associated with just updated case run
512
          var jqCaserunBugCount = jQ('span#' + case_run_id + '_case_bug_count');
513
          if (jqCaserunBugCount.text() == '0') {
514
            jqCaserunBugCount.addClass('have_bug');
515
          }
516
          jqCaserunBugCount.text(returnobj.caserun_bugs_count);
517
518
          // Update the total bugs count of this run
519
          var html = null;
0 ignored issues
show
Unused Code introduced by
The assignment to html seems to be never used. If you intend to free memory here, this is not necessary since the variable leaves the scope anyway.
Loading history...
520
          if (jQ('span#total_run_bug_count a').text() === 'No Bugs') {
521
            html = "<a title='Show All Bugs' href='/runs/" + run_id + "/report/#buglist'>Bugs [" + returnobj.run_bug_count + "]</a>";
522
            jQ('span#total_run_bug_count').html(html);
523
          } else {
524
            html = "Bugs [" + returnobj.run_bug_count + "]";
525
            jQ('span#total_run_bug_count a').html(html);
526
          }
527
528
          return constructCaseRunZone(container, title_container, case_id);
529
        } else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
530
          window.alert(returnobj.response);
531
          return false;
532
        }
533
      };
534
535
      var url = Nitrate.http.URLConf.reverse({ 'name': 'case_run_bug', 'arguments': {'id': case_run_id} });
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
536
537
      jQ.ajax({ url: url, dataType: 'json', data: form_data, success: success_callback });
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
538
    }
539
  });
540
541
  dialog.show();
542
}
543
544
545
function delCaseRun(run_id) {
0 ignored issues
show
Unused Code introduced by
The parameter run_id is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
546
  var caseruns = serializeCaseRunFromInputList('id_table_cases', 'case_run');
547
  var numCaseRuns = caseruns.case_run.length;
548
  if (window.confirm('You are about to delete ' + numCaseRuns + ' case run(s). Are you sure?')) {
549
    postToURL('removecaserun/', caseruns);
550
  }
551
}
552
553
554
// binds the remove buttons for all tags
555
function bindJSRemoveTagButton() {
556
  $('.js-remove-tag').bind('click', function() {
557
    var params = $(this).data('params');
558
    removeRunTag($('.js-tag-ul')[0], params[0], params[1]);
559
  });
560
}
561
562
563
// data is an array of id/name for tags
564
function updateTagContainer(container, data, run_id) {
565
    var html = '';
566
567
    data.forEach(function(element) {
568
        var li = '<li>' + element['name'] +
569
                    '<a href="#" class="js-remove-tag" data-params=\'["'+ run_id + '", "' + element['name'] + '"]\'>' +
570
                        '&nbsp;<i class="fa fa-trash-o"></i>' +
571
                    '</a>' +
572
                 '</li>';
573
        html += li;
574
    });
575
576
    $(container).html(html);
577
    bindJSRemoveTagButton();
578
}
579
580
581
function addRunTag(container, run_id) {
582
    var tag_container = $('#id_tags');
583
    var tag = tag_container.val();
584
585
    if (!tag) {
586
        return false;
587
    }
588
589
    var inner_callback = function(data) {
590
        updateTagContainer(container, data, run_id);
591
        tag_container.val('');
592
    }
593
    jsonRPC('TestRun.add_tag', [run_id, tag], inner_callback);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
594
}
595
596
function removeRunTag(container, run_id, tag) {
597
    var inner_callback = function(data) {
598
        updateTagContainer(container, data, run_id);
599
    }
600
    jsonRPC('TestRun.remove_tag', [run_id, tag], inner_callback);
601
}
602
603
function constructRunCC(container, run_id, parameters) {
604
  var complete = function(t) {
0 ignored issues
show
Unused Code introduced by
The parameter t is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
605
    jQ('.js-remove-cc').bind('click', function() {
606
      var params = jQ(this).data('params');
607
      removeRunCC(params[0], params[1], jQ('.js-cc-ul')[0]);
608
    });
609
    if (jQ('#message').length) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if jQ("#message").length is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
610
      window.alert(jQ('#message').html());
611
      return false;
612
    }
613
  };
614
  var url = '/runs/' + run_id + '/cc/';
615
  jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
616
    'url': url,
617
    'type': 'GET',
618
    'data': parameters,
619
    'success': function (data, textStatus, jqXHR) {
0 ignored issues
show
Unused Code introduced by
The parameter textStatus is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter jqXHR is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
620
      jQ(container).html(data);
621
    },
622
    'complete': function() {
623
      complete();
624
    }
625
  });
626
}
627
628
function addRunCC(run_id, container) {
629
  var user = window.prompt('Please type new email or username for CC.');
630
  if (!user) {
631
    return false;
632
  }
633
  var parameters = {'do': 'add', 'user': user};
634
  constructRunCC(container, run_id, parameters);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
635
}
636
637
function removeRunCC(run_id, user, container) {
638
  var c = window.confirm('Are you sure to delete this user from CC?');
639
640
  if (!c) {
641
    return false;
642
  }
643
644
  var parameters = { 'do': 'remove', 'user': user };
645
  constructRunCC(container, run_id, parameters);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
646
}
647
648
function changeCaseRunAssignee() {
649
  var runs = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]);
650
  if (!runs.length) {
651
    window.alert(default_messages.alert.no_case_selected);
0 ignored issues
show
Bug introduced by
The variable default_messages seems to be never declared. If this is a global, consider adding a /** global: default_messages */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
652
    return false;
653
  }
654
655
  var p = window.prompt('Please type new email or username for assignee');
656
  if (!p) {
657
    return false;
658
  }
659
660
  jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
661
    'url': '/runs/update-assignee/',
662
    'type': 'POST',
663
    'data': { ids: runs, assignee: p },
664
    'success': function (data, textStatus, jqXHR) {
0 ignored issues
show
Unused Code introduced by
The parameter jqXHR is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter textStatus is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
665
      window.location.reload();
666
    },
667
    'error': function (jqXHR, textStatus, errorThrown) {
0 ignored issues
show
Unused Code introduced by
The parameter textStatus is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter errorThrown is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
668
      json_failure(jqXHR);
669
    }
670
  });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
671
}
672
673
function serializeCaseRunFromInputList(table, name) {
674
  var elements;
675
  if (typeof table === 'string') {
676
    elements = jQ('#' + table).parent().find('input[name="case_run"]:checked');
677
  } else {
678
    elements = jQ(table).parent().find('input[name="case_run"]:checked');
679
  }
680
681
  var returnobj_list = [];
682
  elements.each(function(i) {
0 ignored issues
show
Unused Code introduced by
The parameter i is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
683
    if (typeof this.value === 'string') {
684
      returnobj_list.push(this.value);
685
    }
686
  });
687
  if (name) {
688
    var returnobj = {};
689
    returnobj[name] = returnobj_list;
690
    return returnobj;
691
  }
692
693
  return returnobj_list;
694
}
695
696
function serialzeCaseForm(form, table, serialized) {
697
  if (typeof serialized !== 'boolean') {
698
    var serialized = true;
699
  }
700
  var data;
701
  if (serialized) {
702
    data = Nitrate.Utils.formSerialize(form);
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
703
  } else {
704
    data = jQ(form).serialize();
705
  }
706
707
  data['case_run'] = serializeCaseFromInputList(table);
708
  return data;
709
}
710
711
function showCaseRunsWithSelectedStatus(form, status_id) {
712
  form.case_run_status__pk.value = status_id;
713
  fireEvent(jQ(form).find('input[type="submit"]')[0], 'click');
714
}
715
716
function updateBugsActionAdd(case_runs) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
717
  var dialog = new AddIssueDialog({
718
    'extraFormHiddenData': { 'case_runs': case_runs.join() },
719
    'onSubmit': function(e, dialog) {
720
      e.stopPropagation();
721
      e.preventDefault();
722
      var form_data = dialog.get_data();
723
      form_data.bug_id = form_data.bug_id.trim();
724
725
      if (!form_data.bug_id.length) {
726
        return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
727
      }
728
729
      if (!validateIssueID(form_data.bug_validation_regexp, form_data.bug_id)) {
730
        return false;
731
      }
732
733
      jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
734
        url: '/caserun/update-bugs-for-many/',
735
        dataType: 'json',
736
        data: form_data,
737
        success: function(res){
738
          if (res.rc === 0) {
739
            reloadWindow();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
740
          } else {
741
            window.alert(res.response);
742
            return false;
743
          }
744
        }
745
      });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
746
    }
747
  });
748
  dialog.show();
749
}
750
751
function updateBugsActionRemove(case_runs) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
752
  var dialog = new AddIssueDialog({
753
    'action': 'Remove',
754
    'show_bug_id_field': true,
755
    'extraFormHiddenData': { 'case_runs': case_runs.join() },
756
    'onSubmit': function(e, dialog) {
757
      e.stopPropagation();
758
      e.preventDefault();
759
      var form_data = dialog.get_data();
760
      form_data.bug_id = form_data.bug_id.trim();
761
762
      if (!form_data.bug_id.length) {
763
        return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
764
      }
765
766
      if (!validateIssueID(form_data.bug_validation_regexp, form_data.bug_id)) {
767
        return false;
768
      }
769
770
      jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
771
        url: '/caserun/update-bugs-for-many/',
772
        dataType: 'json',
773
        success: function(res) {
774
          if (res.rc == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing res.rc to 0 using the == operator is not safe. Consider using === instead.
Loading history...
775
            reloadWindow();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
776
          } else {
777
            window.alert(res.response);
778
            return false;
779
          }
780
        },
781
        data: form_data,
782
      });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
783
    }
784
  });
785
  dialog.show();
786
}
787
788
function updateBugs(action) {
789
  var runs = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]);
790
  if (!runs.length) {
791
    window.alert(default_messages.alert.no_case_selected);
0 ignored issues
show
Bug introduced by
The variable default_messages seems to be never declared. If this is a global, consider adding a /** global: default_messages */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
792
    return false;
793
  }
794
795
  if (action === "add") {
796
    updateBugsActionAdd(runs);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
797
  } else if (action === "remove") {
798
    updateBugsActionRemove(runs);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
799
  } else {
800
    throw new Error("Unknown operation when update case runs' bugs. This should not happen.");
801
  }
802
}
803
804
function showCommentForm() {
805
  var dialog = getDialog();
806
  var runs = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]);
807
  if (!runs.length) {
808
    return window.alert(default_messages.alert.no_case_selected);
0 ignored issues
show
Bug introduced by
The variable default_messages seems to be never declared. If this is a global, consider adding a /** global: default_messages */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
809
  }
810
  var template = Handlebars.compile(jQ("#batch_add_comment_to_caseruns_template").html());
0 ignored issues
show
Bug introduced by
The variable Handlebars seems to be never declared. If this is a global, consider adding a /** global: Handlebars */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
811
  jQ(dialog).html(template());
812
813
  var commentText = jQ('#commentText');
814
  var commentsErr = jQ('#commentsErr');
815
  jQ('#btnComment').live('click', function() {
816
    var error;
817
    var comments = jQ.trim(commentText.val());
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
818
    if (!comments) {
819
      error = 'No comments given.';
820
    }
821
    if (error) {
822
      commentsErr.html(error);
823
      return false;
824
    }
825
    jQ.ajax({
826
      url: '/caserun/comment-many/',
827
      data: {'comment': comments, 'run': runs.join()},
828
      dataType: 'json',
829
      type: 'post',
830
      success: function(res) {
831
        if (res.rc == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing res.rc to 0 using the == operator is not safe. Consider using === instead.
Loading history...
832
          reloadWindow();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
833
        } else {
834
          commentsErr.html(res.response);
835
          return false;
836
        }
837
      }
838
    });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
839
  });
840
  jQ('#btnCancelComment').live('click', function(){
841
    jQ(dialog).hide();
842
    commentText.val('');
843
  });
844
  jQ(dialog).show();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
845
}
846
847
jQ(document).ready(function(){
848
  jQ('.btnBlueCaserun').mouseover(function() {
849
    jQ(this).find('ul').show();
850
  }).mouseout(function() {
851
    jQ(this).find('ul').hide();
852
  });
853
  jQ('ul.statusOptions a').click(function() {
854
    var option = jQ(this).attr('value');
855
    var object_pks = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]);
856
    if (option == '') {
857
      return false;
858
    }
859
    if (!object_pks.length) {
860
      window.alert(default_messages.alert.no_case_selected);
0 ignored issues
show
Bug introduced by
The variable default_messages seems to be never declared. If this is a global, consider adding a /** global: default_messages */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
861
      return false;
862
    }
863
    if (!window.confirm(default_messages.confirm.change_case_status)) {
864
      return false;
865
    }
866
    updateRunStatus(object_pks, option, reloadWindow);
0 ignored issues
show
Bug introduced by
The variable reloadWindow seems to be never declared. If this is a global, consider adding a /** global: reloadWindow */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
867
  });
868
});
869
870
function get_addlink_dialog() {
871
  return jQ('#addlink_dialog');
872
}
873
874
/*
875
 * Do AJAX request to backend to remove a link
876
 *
877
 * - sender: 
878
 * - link_id: the ID of an arbitrary link.
879
 */
880
function removeLink(sender, link_id) {
881
  jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
882
    url: '/linkref/remove/' + link_id + '/',
883
    type: 'GET',
884
    dataType: 'json',
885
    success: function(data, textStatus, jqXHR) {
0 ignored issues
show
Unused Code introduced by
The parameter jqXHR is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter textStatus is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
886
      if (data.rc !== 0) {
887
        window.alert(data.response);
888
        return false;
889
      }
890
      var li_node = sender.parentNode;
891
      li_node.parentNode.removeChild(li_node);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
892
    },
893
    error: function(jqXHR, textStatus, errorThrown) {
0 ignored issues
show
Unused Code introduced by
The parameter textStatus is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter errorThrown is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
894
      var data = JSON.parse(jqXHR.responseText);
895
      window.alert(data.message);
896
    }
897
  });
898
}
899
900
/*
901
 * Add link to case run
902
 *
903
 * - sender: the Add link button, which is pressed to fire this event.
904
 * - target_id: to which TestCaseRun the new link will be linked.
905
 */
906
function addLinkToCaseRun(sender, case_id, case_run_id) {
907
  var dialog_p = get_addlink_dialog();
908
909
  dialog_p.dialog('option', 'target_id', case_run_id);
910
  // These two options are used for reloading TestCaseRun when successfully.
911
  var container = jQ(sender).parents('.case_content.hide')[0];
912
  dialog_p.dialog('option', 'container', container);
913
  var title_container = jQ(container).prev()[0];
914
  dialog_p.dialog('option', 'title_container', title_container);
915
  dialog_p.dialog('option', 'case_id', case_id);
916
  dialog_p.dialog('open');
917
}
918
919
/*
920
 * Initialize dialog for getting information about new link, which is attached
921
 * to an arbitrary instance of TestCaseRun
922
 */
923
function initialize_addlink_dialog() {
924
  var dialog_p = get_addlink_dialog();
925
926
  dialog_p.dialog({
927
    autoOpen: false,
928
    modal: true,
929
    resizable: false,
930
    height: 300,
931
    width: 400,
932
    open: function() {
933
      jQ(this).unbind('submit').bind('submit', function (e) {
934
        e.stopPropagation();
935
        e.preventDefault();
936
        jQ(this).dialog('widget').find('span:contains("OK")').click();
937
      });
938
    },
939
    buttons: {
940
      "OK": function() {
941
        // TODO: validate name and url
942
        var name = jQ('#testlog_name').attr('value');
943
        var url = jQ('#testlog_url').attr('value');
944
        var target_id = jQ(this).dialog('option', 'target_id');
945
946
        jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
947
          url: '/linkref/add/',
948
          type: 'POST',
949
          data: { name: name, url: url, target_id: target_id },
950
          dataType: 'json',
951
          success: function(data, textStatus, jqXHR) {
0 ignored issues
show
Unused Code introduced by
The parameter textStatus is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter jqXHR is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
952
            if (data.rc !== 0) {
953
              window.alert(data.response);
954
              return false;
955
            }
956
            dialog_p.dialog('close');
957
958
            // Begin to construct case run area
959
            var container = dialog_p.dialog('option', 'container');
960
            var title_container = dialog_p.dialog('option', 'title_container');
961
            var case_id = dialog_p.dialog('option', 'case_id');
962
            constructCaseRunZone(container, title_container, case_id);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
963
          },
964
          error: function (jqXHR, textStatus, errorThrown) {
0 ignored issues
show
Unused Code introduced by
The parameter textStatus is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter errorThrown is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
965
            var data = JSON.parse(jqXHR.responseText);
966
            window.alert(data.response);
967
          }
968
        });
969
      },
970
      "Cancel": function() {
971
        jQ(this).dialog('close');
972
      }
973
    },
974
    beforeClose: function() {
975
      // clean name and url for next input
976
      jQ('#testlog_name').val('');
977
      jQ('#testlog_url').val('');
978
979
      return true;
980
    },
981
    /* ATTENTION: target_id can be determined when open this dialog, and
982
     * this must be set
983
     */
984
    target_id: null
985
  });
986
}
987
988
989
/*
990
 * Toggle TestCaseRun panel to edit a case run in run page.
991
 *
992
 * Arguments:
993
 * options.casrunContainer:
994
 * options.expandPaneContainer:
995
 * options.caseId:
996
 * options.caserunId:
997
 * options.caseTextVersion:
998
 * options.callback:
999
 */
1000
function toggleTestCaseRunPane(options) {
1001
  var container = options.caserunRowContainer;
1002
  var content_container = options.expandPaneContainer;
1003
  var callback = options.callback;
1004
1005
  content_container.toggle();
1006
1007
  if (content_container.find('.ajax_loading').length) {
1008
    var url = '/case/' + options.caseId + '/caserun-detail-pane/';
1009
    var data = { case_run_id: options.caserunId, case_text_version: options.caseTextVersion };
1010
1011
    jQ.get(url, data, function(data, textStatus) {
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Unused Code introduced by
The parameter textStatus is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1012
      content_container.html(data);
1013
      callback();
1014
    }, 'html');
1015
  }
1016
1017
  toggleExpandArrow({ caseRowContainer: container, expandPaneContainer: content_container });
1018
}
1019